package com.cangxuan.manage.utils;

import lombok.extern.slf4j.Slf4j;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 安全工具类
 */
@Slf4j
public class SecurityUtils {

    public static String md5(String source) {
        //创建一个消息摘要对象
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        //添加要获取摘要的数据
        digest.update(source.getBytes(StandardCharsets.UTF_8));
        //获取摘要
        byte[] results = digest.digest();
        return new BigInteger(1, results).toString(16);
    }

    public static void main(String[] args) {

        log.info(md5("admin123456"));

    }


}
